package com.colorlight.cloud.complete.entity.instructions;

import com.colorlight.cloud.complete.api.CompleteEntityScheduleActions;
import com.colorlight.cloud.complete.entity.po.ReceiverParameterRequest;
import com.colorlight.iot.proto.complete.instruction.CompleteInstruction;
import com.google.protobuf.ByteString;
import lombok.*;
import lombok.extern.slf4j.Slf4j;

import java.io.Serializable;
import java.util.List;
import java.util.stream.Collectors;

/**
 * 固化接收卡参数
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder
@Slf4j
public class SetReceiverParameterRequest implements CompleteEntityScheduleActions {

    @Data
    @NoArgsConstructor
    @AllArgsConstructor
    @Builder
    public static class InputMsg implements Serializable {
        /**
         * 接收卡参数请求
         */
        private List<ReceiverParameterRequest> receiverParameterRequest;
    }

    @Data
    @NoArgsConstructor
    @Builder
    public static class OutputMsg implements Serializable {
    }

    private InputMsg inputMsg;
    private OutputMsg outputMsg;

    @Override
    public ByteString objectConvertBytes() {
        final CompleteInstruction.SetReceiverParameterRequest.InputMsg.Builder inputMsg =
                CompleteInstruction.SetReceiverParameterRequest.InputMsg.newBuilder();
        SetReceiverParameterRequest.InputMsg thisInput = this.getInputMsg();
        inputMsg.addAllReceiverParameterRequest(thisInput.getReceiverParameterRequest().stream().map(ReceiverParameterRequest::toProto).collect(Collectors.toList()));
        final CompleteInstruction.SetReceiverParameterRequest.Builder builder =
                CompleteInstruction.SetReceiverParameterRequest.newBuilder();
        builder.setInput(inputMsg);
        return builder.build().toByteString();
    }

    @Override
    public SetReceiverParameterRequest byteConvertObject(ByteString bytes) {
        this.setOutputMsg(new SetReceiverParameterRequest.OutputMsg());
        return this;
    }

}

